package cn.iocoder.yudao.module.crossborder.platform.service.platformapilog;

import cn.hutool.core.collection.CollUtil;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import cn.iocoder.yudao.module.crossborder.platform.controller.admin.platformapilog.vo.*;
import cn.iocoder.yudao.module.crossborder.platform.dal.dataobject.platformapilog.PlatformApiLogDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;

import cn.iocoder.yudao.module.crossborder.platform.dal.mysql.platformapilog.PlatformApiLogMapper;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.diffList;
import static cn.iocoder.yudao.module.crossborder.platform.enums.ErrorCodeConstants.*;

/**
 * 跨境电商平台API调用日志 Service 实现类
 *
 * @author 芋道源码
 */
@Service
@Validated
public class PlatformApiLogServiceImpl implements PlatformApiLogService {

    @Resource
    private PlatformApiLogMapper platformApiLogMapper;

    @Override
    public Long createPlatformApiLog(PlatformApiLogSaveReqVO createReqVO) {
        // 插入
        PlatformApiLogDO platformApiLog = BeanUtils.toBean(createReqVO, PlatformApiLogDO.class);
        platformApiLogMapper.insert(platformApiLog);

        // 返回
        return platformApiLog.getId();
    }

    @Override
    public void updatePlatformApiLog(PlatformApiLogSaveReqVO updateReqVO) {
        // 校验存在
        validatePlatformApiLogExists(updateReqVO.getId());
        // 更新
        PlatformApiLogDO updateObj = BeanUtils.toBean(updateReqVO, PlatformApiLogDO.class);
        platformApiLogMapper.updateById(updateObj);
    }

    @Override
    public void deletePlatformApiLog(Long id) {
        // 校验存在
        validatePlatformApiLogExists(id);
        // 删除
        platformApiLogMapper.deleteById(id);
    }

    @Override
        public void deletePlatformApiLogListByIds(List<Long> ids) {
        // 删除
        platformApiLogMapper.deleteByIds(ids);
        }


    private void validatePlatformApiLogExists(Long id) {
        if (platformApiLogMapper.selectById(id) == null) {
            throw exception(PLATFORM_API_LOG_NOT_EXISTS);
        }
    }

    @Override
    public PlatformApiLogDO getPlatformApiLog(Long id) {
        return platformApiLogMapper.selectById(id);
    }

    @Override
    public PageResult<PlatformApiLogDO> getPlatformApiLogPage(PlatformApiLogPageReqVO pageReqVO) {
        return platformApiLogMapper.selectPage(pageReqVO);
    }

}